// pages/complaints/index.js
var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    items: [
      { value: '欺诈', checked: 0, },
      { value: '色情', checked: 0, },
      { value: '政治谣言', checked: 0, },
      { value: '诱导分享', checked: 0, },
      { value: '恶意营销', checked: 0, },
      { value: '隐私信息收集', checked: 0, },
    ],
    selet_items: '',
  },
  checkboxChange: function (e) {
    console.log('checkbox发生change事件，携带value值为：', e.detail.value);
    var selet_items = e.detail.value;
    console.log(selet_items);
    this.setData({ selet_items: selet_items, })
  },
  formSubmit: function (e) {
    var that = this;
    var formId = e.detail.formId;
    var items = that.data.items;
    console.log(5555);
    console.log(typeof e == '');
    if (that.data.selet_items == '') {
      prompt('请选择原因', 'loading')
      return;
    }
    if (e.detail.value.use_phone == '') {
      prompt('请输入手机', 'loading')
      return;
    }
    if (!(/^1(3|4|5|7|8)\d{9}$/.test(e.detail.value.use_phone))) {
      prompt('手机号码有误', 'loading');
      return;
    }
    wx.showModal({
      title: '确认提交？',
      content: '请问您确认提交吗？',
      success: function (res) {
        if (res.confirm) {
          console.log('用户点击确定')
          app.token_md5();
          // 我们已经收到您的反馈, 感谢您的理解与支持
          wx.request({
            url: app.url2 + 'api/complaintAdd',
            data: {
              openid: wx.getStorageSync('openid'),
              token: wx.getStorageSync('token_md5'),
              message: that.data.selet_items,
              phone: e.detail.value.use_phone,
              id: that.data.id,
              formId: formId
            },
            header: { 'content-type': 'application/json' },
            success: function (res) {
              console.log(555);
              console.log(res);
              if (res.data == "提交成功！") {
                prompt('提交成功！', 'success');
                setTimeout(function () { wx.navigateBack({ delta: '' }) }, 1200);//返回上一个页面
              } else {
                prompt('提交失败', 'loading');
              }
            },
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      id: options.id,
    })
  }

})


// 提示
function prompt(text, stat) {
  //提示信息
  wx.showToast({
    title: text,
    icon: stat,
    duration: 1200,
  })
};